package com.zj.healthmanage.service.impl;

import com.zj.healthmanage.mapper.MemberMapper;
import com.zj.healthmanage.mapper.OrderlistMapper;
import com.zj.healthmanage.service.StatementService;
import com.zj.healthmanage.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * @author 张杰
 * @date 2022/2/25 0025 16:55
 * @description
 */
@Service
public class StatementServiceImpl implements StatementService {

    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private OrderlistMapper orderlistMapper;

    @Override
    public Map<String, Object> queryBusiness() throws Exception {
        //获得当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获得本周一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获得本月第一天的日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //今日新增会员数
        Integer todayNewMember = memberMapper.queryMemberCountByDate(today);
        //总会员数
        Integer totalMember = memberMapper.queryMemberTotalCount();
        //本周新增会员数
        Integer thisWeekNewMember = memberMapper.queryMemberCountAfterDate(thisWeekMonday);
        //本月新增会员数
        Integer thisMonthNewMember = memberMapper.queryMemberCountAfterDate(firstDay4ThisMonth);
        //今日预约数
        Integer todayOrderNumber = orderlistMapper.queryOrderCountByDate(today);
        //本周预约数
        Integer thisWeekOrderNumber = orderlistMapper.queryOrderCountAfterDate(thisWeekMonday);
        //本月预约数
        Integer thisMonthOrderNumber = orderlistMapper.queryOrderCountAfterDate(firstDay4ThisMonth);
        //今日到诊数
        Integer todayVisitsNumber = orderlistMapper.queryVisitsCountByDate(today);
        //本周到诊数
        Integer thisWeekVisitsNumber = orderlistMapper.queryVisitsCountAfterDate(thisWeekMonday);
        //本月到诊数
        Integer thisMonthVisitsNumber = orderlistMapper.queryVisitsCountAfterDate(firstDay4ThisMonth);
        //热门套餐（取前4）
        List<Map> hotSetmeal = orderlistMapper.queryHotSetmeal();
        Map<String,Object> result = new HashMap<>();
        result.put("reportDate",today);
        result.put("todayNewMember",todayNewMember);
        result.put("totalMember",totalMember);
        result.put("thisWeekNewMember",thisWeekNewMember);
        result.put("thisMonthNewMember",thisMonthNewMember);
        result.put("todayOrderNumber",todayOrderNumber);
        result.put("thisWeekOrderNumber",thisWeekOrderNumber);
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);
        result.put("todayVisitsNumber",todayVisitsNumber);
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        result.put("hotSetmeal",hotSetmeal);
        return result;
    }
}
